package net.dgg.dggcloud.service.jrcrm.service.log;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;

import net.dgg.dggcloud.service.common.base.service.BaseService;
import net.dgg.dggcloud.service.entity.user.User;
import net.dgg.dggcloud.service.jrcrm.dao.log.SysModifyUserRecordDao;
import net.dgg.dggcloud.service.service.user.UserService;

/**
 * 修改用户信息记录Service
 * 
 * @Title: SysOpreateModuleRecordService
 * @Description:
 * @Auther: 雷力
 * @Date: 2018-11-09 14:51:50
 *
 */
@Service
public class SysModifyUserRecordService extends BaseService implements SysRecordService {

	@Autowired
	private SysModifyUserRecordDao dao;
	@Autowired
	private UserService userService;

	/**
	 * 插入数据
	 * 
	 * @param record
	 */
	@SuppressWarnings("unchecked")
	public void insert(Map<String, Object> map) {
		Map<String, Object> vuser = (Map<String, Object>) map.get("vuser");
		User user = userService.getUserById(Long.valueOf(vuser.get("id").toString()));
		map.put("vuserName", user.getName());
		map.put("vuserLoginname", user.getLoginName());
		Iterator<String> keys = vuser.keySet().iterator();
		while (keys.hasNext()) {
			String key = keys.next();
			if (vuser.get(key) == null) {
				vuser.remove(key);
			}
		}
		map.put("content", JSON.toJSONString(vuser));
		logger.error("=====>"+SysModifyUserRecordService.class+"=====>插入数据...");
		dao.insert(map);
	}

	@SuppressWarnings("rawtypes")
	public List<Map> listModifyUserRecordByMap(Map<String, Object> map) {
		return dao.listModifyUserRecordByMap(map);
	}

	public Integer countModifyUserRecordByMap(Map<String, Object> map) {
		return dao.countModifyUserRecordByMap(map);
	}
}
